package com.csd.action.manager;

import java.util.ArrayList;
import java.util.List;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.pojo.Message;
import com.csd.pojo.Project;
import com.csd.service.IProjectService;
import com.csd.vo.ProjectVO;
import com.opensymphony.xwork2.ActionContext;

/**
 * 查看历史项目
 * @author 三木
 *	<br> 创建于2009-12-17
 */
public class ProjectHistoryAction {
	
	private Integer numInPage;

	private Integer currPage;
	
	private Integer totalPage;

	public Integer getNumInPage() {
		return numInPage;
	}

	public void setNumInPage(Integer numInPage) {
		this.numInPage = numInPage;
	}

	public Integer getCurrPage() {
		return currPage;
	}

	public void setCurrPage(Integer currPage) {
		this.currPage = currPage;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	private List<ProjectVO> projectHistoryList;
	
	private IProjectService projectService;
	
	public List<ProjectVO> getProjectHistoryList() {
		return projectHistoryList;
	}

	public void setProjectHistoryList(List<ProjectVO> projectHistoryList) {
		this.projectHistoryList = projectHistoryList;
	}

	public IProjectService getProjectService() {
		return projectService;
	}

	public void setProjectService(IProjectService projectService) {
		this.projectService = projectService;
	}

	public String execute() throws Exception {
		String text = ActionResult.fail;
		//projectHistoryList = projectService.listHistoryProject();
		//历史项目列表		
		List<ProjectVO> old = projectService.listHistoryProject();
		
		//列表
		if( this.currPage == null  || this.currPage <= 0 )
			this.currPage = 1;
		
		if( this.numInPage == null || this.numInPage <= 0)
			this.numInPage = IConstant.numInPage;
		
		if(projectHistoryList == null)
		{
			projectHistoryList = new ArrayList<ProjectVO>();
		}
		
		if(old == null)
		{
			old = new ArrayList<ProjectVO>();
		}
		
		projectHistoryList.clear();
		
		for(int i = (this.currPage-1)*this.numInPage; 
				i < this.currPage*this.numInPage && i < old.size(); 
				i++)
		{
			projectHistoryList.add( old.get(i) );
		}
		

		this.totalPage = old.size() / this.numInPage;
		
		if(old.size() % this.numInPage != 0)
			this.totalPage++;
		
		text = ActionResult.success;
		return text;
	}
}
